package demo.logger;

import java.io.IOException;
import java.util.Arrays;
import java.util.logging.*;

/**
 *
 * 日志，默认转发到控制台
 * @author small瑞
 */
public class LoggerDemo01 {
    public static void main(String[] args) throws IOException {
        Logger logger = Logger.getLogger(LoggerDemo01.class.getName());

        System.out.println(logger.getName());

        System.out.println(logger.getLevel());

        System.out.println(logger.getFilter());

        System.out.println(Arrays.toString(logger.getHandlers()));

        System.out.println(logger.getParent());

        logger.setLevel(Level.ALL);

        System.out.println(logger.getLevel());

        System.out.println(logger.getResourceBundleName());

        System.out.println(logger.getParent().getResourceBundleName());



        Handler[] handlers = logger.getHandlers();

        System.out.println(Arrays.toString(handlers));

        System.out.println("-------------------------");

        for(Handler handler : handlers){
            System.out.println(handler.getFilter());
            System.out.println(handler.getLevel());
            System.out.println(handler.getEncoding());
            System.out.println(handler.getFormatter());
        }

        handlers = logger.getParent().getHandlers();

        System.out.println("------------------------");

        for(Handler handler : handlers){
            System.out.println(handler.getFilter());
            System.out.println(handler.getLevel());
            System.out.println(handler.getEncoding());
            System.out.println(handler.getFormatter());
        }

        Handler handler = new ConsoleHandler();

        handler.setLevel(Level.ALL);
        handler.setEncoding("UTF-8");

        logger.addHandler(handler);

        System.out.println("----------------------------");

        logger.info("消息");

        logger.warning("警告");

        logger.config("config");

        logger.severe("severe");

        logger.fine("fine");

        logger.finer("finer");

//        logger.setUseParentHandlers(false);
//        String pattern = "";
//        Handler handler = new FileHandler(pattern , );
//        logger.addHandler(handler);
    }
}
